﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>Overriding or Disabling Hotkeys | AutoHotkey v2</title>
<meta name="description" content="Learn how to override or disable built-in Windows hotkeys." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>

<body>
<h1>Overriding or Disabling Hotkeys</h1>

<p>You can disable all built-in Windows hotkeys except <kbd>Win</kbd>+<kbd>L</kbd> and <kbd>Win</kbd>+<kbd>U</kbd> by making the following change to the registry (this should work on all OSes but a reboot is probably required):</p>
<pre>HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
NoWinKeys REG_DWORD 0x00000001 (1)</pre>
<p>But read on if you want to do more than just disable them all.</p>
<p>Hotkeys owned by another application can be overridden or disabled simply by assigning them to an action in the script. The most common use for this feature is to change the hotkeys that are built into Windows itself. 例如, if you wish <kbd>Win</kbd>+<kbd>E</kbd> (the shortcut key that launches Windows Explorer) to perform some other action, use this:</p>
<pre>#e::
MsgBox "This hotkey is now owned by the script."
return</pre>
<p>In the next example, the <kbd>Win</kbd>+<kbd>R</kbd> hotkey, which is used to open the RUN window, is completely disabled:</p>
<pre>#r::return</pre>
<p>Similarly, to disable both <kbd>Win</kbd> keys, use this:</p>
<pre>LWin::return
RWin::return</pre>
<p>To disable or change an application's non-global hotkey (that is, a shortcut key that only works when that application is the active window), consider the following example which disables <kbd>Control</kbd>+<kbd>P</kbd> (Print) only for Notepad, leaving the key in effect for all other types of windows:</p>
<pre>$^p::
if WinActive("ahk_class Notepad")
    return  <em>; i.e. do nothing, which causes Control-P to do nothing in Notepad.</em>
Send "^p"
return</pre>
<p>In the above example, the $ prefix is needed so that the hotkey can &quot;send itself&quot; without activating itself (which would otherwise trigger a warning dialog about an infinite loop). See also: <a href="../Hotkeys.htm#Context">context-sensitive hotkeys</a>.</p>
<p>You can try out any of the above examples by copying them into a new text file such as &quot;Override.ahk&quot;, then launching the file.</p>
</body>
</html>